﻿using UnityEngine;
using System.Collections;

public class ClickMouse : MonoBehaviour {

	private Ray ray;
	private RaycastHit hit;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		// 0  left
		// 1  right
		//	2 mid
	if (Input.GetMouseButtonDown (0)) {
			//Ray 
				ray = Camera.main.ScreenPointToRay(Input.mousePosition);

			//RaycastHit hit;
			if(Physics.Raycast(ray,out hit ,100))
			{
				if(hit.transform.GetComponent<MemoryCards>()!=null)
					StartCoroutine("Click");

			}
		}
	}
	IEnumerator Click()
	{
		yield return new WaitForSeconds (.5f);
		hit.transform.GetComponent<MemoryCards>().showCard();
	}
}
